package gwt.seca.client.agents;

import javax.vecmath.Vector3f;

public class Ernest8Anim extends AbstractAnim {

	final static int ANIM_MOVE = 1;
	final static int ANIM_BUMP = 2;
	final static int ANIM_TURN_LEFT = 3;
	final static int ANIM_TURN_RIGHT = 4;
//	final static int ANIM_TOUCH_FORWARD = 5;
//	final static int ANIM_TOUCH_LEFT = 6;
//	final static int ANIM_TOUCH_RIGHT = 7;
	
	public Ernest8Anim(Ernest8Model model) {
		super(model);
		mModel = model;
	}
	
	protected void startImpl(Vector3f trans, Vector3f rot) {
		float dist = trans.length();
		float rotZ = rot.getZ();
		switch (mAnimID) {
		case ANIM_MOVE:
			mNumberOfCycles = 0;
			mExtremeCephalothoraxTrans.set(dist, 0, 0);
			mExtremeCephalothoraxRot.set(0, 0, 0);
			mNumberOfCycles2 = 0;
			mExtremeFrontLegsRot.set(0, 0, 0);
			mExtremeLeftLegsRot.set(0, 0, -20);
			mExtremeRightLegsRot.set(0, 0, 20);
			mExtremeBackLegsRot.set(0, 0, 0);
			mExtremeTailRot.set(0, 0, 0);
			break;
		case ANIM_BUMP:
			if (dist > 0)
				mNumberOfCycles = 0;
			else
				mNumberOfCycles = 1;
			mExtremeCephalothoraxTrans.set(dist, 0, 0);
			mExtremeCephalothoraxRot.set(0, 20, 0);
			mNumberOfCycles2 = 1;
			mExtremeFrontLegsRot.set(0, 0, 0);
			mExtremeLeftLegsRot.set(0, 0, -20);
			mExtremeRightLegsRot.set(0, 0, 20);
			mExtremeBackLegsRot.set(0, 0, 0);
			mExtremeTailRot.set(0, 30, 0);
			if (mModel.mDiscrete)
				mNumberOfCycles = 1;
				mExtremeCephalothoraxTrans.set(.2f, 0, 0);
			break;
		case ANIM_TURN_LEFT:
			mNumberOfCycles = 0;
			mExtremeCephalothoraxTrans.set(0, 0, 0);
			mExtremeCephalothoraxRot.set(0, 0, rotZ);
			mNumberOfCycles2 = 1;
			mExtremeFrontLegsRot.set(0, 0, 0);
			mExtremeLeftLegsRot.set(0, 0, 5);
			mExtremeRightLegsRot.set(0, 0, 20);
			mExtremeBackLegsRot.set(0, 0, 0);
			mExtremeTailRot.set(0, 0, -rotZ/3f);
			break;
		case ANIM_TURN_RIGHT:
			mNumberOfCycles = 0;
			mExtremeCephalothoraxTrans.set(0, 0, 0);
			mExtremeCephalothoraxRot.set(0, 0, rotZ);
			mNumberOfCycles2 = 1;
			mExtremeFrontLegsRot.set(0, 0, 0);
			mExtremeLeftLegsRot.set(0, 0, -20);
			mExtremeRightLegsRot.set(0, 0, -5);
			mExtremeBackLegsRot.set(0, 0, 0);
			mExtremeTailRot.set(0, 0, -rotZ/3f);
			break;
		default:
			mAnimID = 0;
			mModel = null;
		}
	}
	public void updateImpl(float scale, float scale2) {
		mModel.mCephalothoraxTrans.scale(scale, mExtremeCephalothoraxTrans);
		mModel.mCephalothoraxRot.scale(scale, mExtremeCephalothoraxRot);
		mModel.mFrontLegsRot.scale(scale2, mExtremeFrontLegsRot);
		mModel.mLeftLegsRot.scale(scale2, mExtremeLeftLegsRot);
		mModel.mRightLegsRot.scale(scale2, mExtremeRightLegsRot);
		mModel.mBackLegsRot.scale(scale2, mExtremeBackLegsRot);
		mModel.mTailRot.scale(scale2, mExtremeTailRot);
	}
	public void stopImpl() {
		mModel.mCephalothoraxTrans.set(0, 0, 0);
		mModel.mCephalothoraxRot.set(0, 0, 0);
		mModel.mFrontLegsRot.set(0, 0, 0);
		mModel.mLeftLegsRot.set(0, 0, 0);
		mModel.mRightLegsRot.set(0, 0, 0);
		mModel.mBackLegsRot.set(0, 0, 0);
		mModel.mTailRot.set(0, 0, 0);
	}
	
	protected Ernest8Model mModel;
	public Vector3f mExtremeCephalothoraxTrans = new Vector3f();
	public Vector3f mExtremeCephalothoraxRot = new Vector3f();
	public Vector3f mExtremeFrontLegsRot = new Vector3f();
	public Vector3f mExtremeLeftLegsRot = new Vector3f();
	public Vector3f mExtremeRightLegsRot = new Vector3f();
	public Vector3f mExtremeBackLegsRot = new Vector3f();
	public Vector3f mExtremeTailRot = new Vector3f();
}
